// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

namespace SnapObjects.Data
{
    public class UpdateResult : IDbResult
    {
        /// <summary>
        ///     Gets the amount of rows that are inserted when saving the data changes to the database.
        /// </summary>
        public int InsertedCount { get; set; }

        /// <summary>
        ///     Gets the amount of rows that are deleted when saving the data changes to the database.
        /// </summary>
        public int DeletedCount { get; set; }

        /// <summary>
        ///     Gets the amount of rows that are modified when saving the data changes to the database.
        /// </summary>
        public int ModifiedCount { get; set; }

        /// <summary>
        ///     Gets the amount of rows that are affected when saving the data changes to the database.
        /// </summary>
        public int AffectedCount => this.InsertedCount + this.DeletedCount + this.ModifiedCount;

        /// <summary>
        ///     Gets whether the operation is cancelled when saving the data changes to the database.
        /// </summary>
        public bool Cancelled { get; set; }

        public static UpdateResult operator +(UpdateResult left, UpdateResult right)
        {
            left.DeletedCount += right.DeletedCount;
            left.ModifiedCount += right.ModifiedCount;
            left.InsertedCount += right.InsertedCount;

            return left;
        }
    }
}
